package com.learn.educommentboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.learn.eduapi.entity.comment.CourseComment;
import com.learn.eduapi.entity.comment.CourseCommentFavoriteRecord;
import com.learn.eduapi.entity.course.Course;
import com.learn.educommentboot.mapper.CourseCommentDao;
import com.learn.educommentboot.service.CourseCommentService;
import com.learn.educommentboot.util.RedisUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CourseCommentServiceImpl implements CourseCommentService {
    @Autowired
    private CourseCommentDao courseCommentDao;

    @Override
    public CourseCommentFavoriteRecord selectByCourseCommentFavoriteRecordId(Integer userId, Integer commentId) {
        return courseCommentDao.selectByCourseCommentFavoriteRecordId(userId,commentId);
    }

    @Override
    public int delComment(Integer commentId) {
        courseCommentDao.delCommentFavorite(commentId);
        return courseCommentDao.delComment(commentId);
    }

    @Override
    public int delAmdinCommentFavorite(Integer id) {
        return courseCommentDao.delAmdinCommentFavorite(id);
    }

    @Override
    public List<CourseCommentFavoriteRecord> getCrouseRavoritesUserList(Integer Id) {
        return courseCommentDao.getCrouseRavoritesUserList(Id);
    }

    @Override
    public List<CourseComment> getAdminCommentRecord(String find,int page, int size) {
        return courseCommentDao.getAdminCommentRecord(find,page,size);
    }

    @Override
    public int updateAdminComment(CourseComment courseComment, Wrapper<CourseComment> wrapper) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = sdf.format(date);
        courseComment.setUpdateTime(dateString);
        return courseCommentDao.update(courseComment,wrapper);
    }

    @Override
    public List<CourseComment> getCommentList(String find, Integer page, Integer size) {
        return courseCommentDao.getCommentList(find,page,size);
    }

    @Override
    public List<CourseComment> selectgetAllComment(Integer userId, int id, int pageNum, int pageSize) {
        return courseCommentDao.selectgetAllComment(userId,id,pageNum,pageSize);
    }


    @Override
    public void addComment(CourseComment comment) {
        courseCommentDao.addComment(comment);
    }

    @Override
    public void addCommentFavorite(CourseCommentFavoriteRecord courseCommentFavoriteRecord) {
        courseCommentDao.addCommentFavorite(courseCommentFavoriteRecord);
    }

    @Override
    public void OneaddCommentFavorite(CourseCommentFavoriteRecord courseCommentFavoriteRecord) {
        courseCommentDao.OneaddCommentFavorite(courseCommentFavoriteRecord);
    }

    @Override
    public void updateComment(String updateTime, Integer commentId, Integer userId) {
        courseCommentDao.updateComment(updateTime,commentId,userId);
    }

    @Override
    public int updateCommentSave(String updateTime, Integer commentId, Integer userId) {
        return courseCommentDao.updateCommentSave(updateTime,commentId,userId);
    }

    @Override
    public Integer selectLikeCount(Integer commentId) {
        return courseCommentDao.selectLikeCount(commentId);
    }

    @Override
    public void updateLikeCount(Integer i, Integer commentId) {
        courseCommentDao.updateLikeCount(i,commentId);
    }
}
